#!/usr/bin/env python

import sys
import itertools

def main():
    for path_id, grp in itertools.groupby((l.strip().split('\t') for l in sys.stdin), key=lambda spl: spl[0]):
        grp = list(grp)
        genes_founded, genes_all, path_desc = grp[0][1:4]
        print "%s/%s\t%s\t%s" % (genes_founded, genes_all, path_id, path_desc)
        uniq_functions = dict((function, (prob, gene_id)) for prob, gene_id, function in sorted(((float(g[4]), g[5], g[6]) for g in grp)))
        for function, (prob, gene_id) in sorted(uniq_functions.iteritems(), key=lambda i:i[1]):
            print "\t%s\t%s\t%s" % (prob, gene_id, function)
        print


if __name__ == "__main__":
    main()

